#include <bits/stdc++.h>

using namespace std;
typedef long long LL;

const int N=1e3+10;

LL n,ret=LLONG_MAX;
LL a[N],f[N];

int main() 
{
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>a[i];
		f[i]=f[i-1]+a[i];
	}
	
	for(int i=1;i<=n-3;i++)
		for(int j=i+1;j<=n-2;j++)
			for(int a=j+1;a<=n-1;a++)
				for(int b=a+1;b<=n;b++)
				{
					LL t=abs((f[b]-f[a-1])-(f[j]-f[i-1]));
					ret=min(ret,t);
				}

	cout<<ret<<endl;
	return 0;
}
